package com.lkd.controller;

import com.lkd.result.Result;
import com.lkd.service.OrderCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/order-service/report")
public class OrderCollectController {

    @Autowired
    private OrderCollectService orderCollectService;

    /**
     * 统计指定时间段内的订单数量
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/orderCount")
    public Result orderCount(@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "start") LocalDate start,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "end") LocalDate end){
        int count = orderCollectService.orderCount(start,end);
        return Result.success(count);
    }

    /**
     * 统计指定时间段内的销售额数量
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/orderAmount")
    public Result orderAmount(@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "start") LocalDate start,
                             @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(value = "end") LocalDate end){
        int count = orderCollectService.orderAmount(start,end);
        return Result.success(count);
    }
}
